import FSMBlackboard from "./FSMBlackboard";
import FSMCondition from "./FSMCondition";

export default class FSMTransition {
    public fromId: number;
    public toId: number;
    public conditions: FSMCondition<any>[];

    constructor(fromId: number, toId: number) {
        this.conditions = [];
        this.fromId = fromId;
        this.toId = toId;
    }

    public addCondition(condition: FSMCondition<any>) {
        if (this.conditions.indexOf(condition) !== -1) return;
        this.conditions.push(condition);
    }
    
    public tick(data: FSMBlackboard) {
        for (let i = 0, len = this.conditions.length; i < len; i++) {
            if (!this.conditions[i].tick(data)) {
                return false;
            }
        }
        return true;
    }
}
